package com.stars.easyms.logger.support.logback.springboot.version2xx;

import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.action.NOPAction;
import ch.qos.logback.core.joran.spi.ElementSelector;
import ch.qos.logback.core.joran.spi.RuleStore;
import org.springframework.boot.logging.LoggingInitializationContext;
import org.springframework.core.env.Environment;

/**
 * <p>className: EasyMsSpringBootJoranConfigurator</p>
 * <p>description: 因原SpringBootJoranConfigurator权限问题新增相同代码的类</p>
 *
 * @author guoguifang
 * @date 2019-11-14 16:35
 * @since 1.4.0
 */
public class EasyMsSpringBootJoranConfigurator extends JoranConfigurator {

    private LoggingInitializationContext initializationContext;

    public EasyMsSpringBootJoranConfigurator(LoggingInitializationContext initializationContext) {
        this.initializationContext = initializationContext;
    }

    @Override
    public void addInstanceRules(RuleStore rs) {
        super.addInstanceRules(rs);
        Environment environment = this.initializationContext.getEnvironment();
        rs.addRule(new ElementSelector("configuration/springProperty"),
                new EasyMsSpringPropertyAction(environment));
        rs.addRule(new ElementSelector("*/springProfile"),
                new EasyMsSpringProfileAction(environment));
        rs.addRule(new ElementSelector("*/springProfile/*"), new NOPAction());
    }
}